package com.ruoyi.api.v1;

import com.ruoyi.cinema.BO.FilmScheduleBO;
import com.ruoyi.cinema.domain.Film;
import com.ruoyi.cinema.domain.FilmStill;
import com.ruoyi.cinema.mapper.FilmMapper;
import com.ruoyi.cinema.service.IFilmService;
import com.ruoyi.cinema.service.IFilmStillService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController("v1_Film")
@RequestMapping(value = "api/v1/film")
public class FilmController extends BaseController {

    @Autowired
    private IFilmService filmService;
    @Autowired
    private FilmMapper filmMapper;
    @Autowired
    private IFilmStillService filmStillService;


    @GetMapping("/list")
    public TableDataInfo list(FilmScheduleBO filmScheduleBO) {
        startPage();
        List<Film> list = filmMapper.selectFilmWithSchedule(filmScheduleBO);
        return getDataTable(list);
    }

    @GetMapping("/listCinemaFilm")
    public TableDataInfo listCinemaFilm(FilmScheduleBO filmScheduleBO) {
        startPage();
        List<Film> list = filmMapper.selectFilmWithSchedule(filmScheduleBO);
        return getDataTable(list);
    }



    @RequestMapping(value = "/get")
    public AjaxResult getInfo(Film film) {
        Film fl = filmService.selectFilmById(film.getId());
        FilmStill filmStill = new FilmStill();
        filmStill.setFilmId(fl.getId());
        List<FilmStill> filmStillList= filmStillService.selectFilmStillList(filmStill);
        fl.setFilmStillList(filmStillList.stream().map(FilmStill::getUrl).collect(Collectors.toList()));
        return AjaxResult.success(fl);
    }


}
